package com.atguigu.auth.controller;

import com.atguigu.auth.service.OaProcessTypeService;
import com.atguigu.common.Result;
import com.atguigu.model.process.ProcessType;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: ProcessTypeController
 * Package: com.atguigu.auth.controller
 * Description:
 *
 * @Author 蹇泽阳
 * @Create 2023/11/21 10:25
 * @Version 1.0
 */
@Api(value = "审批类型", tags = "审批类型")
@RestController
@RequestMapping(value = "/admin/process/processType")
public class ProcessTypeController {
  @Autowired
  private OaProcessTypeService processTypeService;
  
  @PreAuthorize("hasAuthority('bnt.processType.list')")
  @ApiOperation(value = "获取分页列表")
  @GetMapping("{page}/{limit}")
  public Result index(@PathVariable Long page,
                      @PathVariable Long limit) {
    Page<ProcessType> pageParam = new Page<>(page, limit);
    IPage<ProcessType> pageModel = processTypeService.page(pageParam);
    return Result.ok(pageModel);
  }
  
  @PreAuthorize("hasAuthority('bnt.processType.list')")
  @ApiOperation(value = "获取")
  @GetMapping("get/{id}")
  public Result get(@PathVariable Long id) {
    ProcessType processType = processTypeService.getById(id);
    return Result.ok(processType);
  }
  
  @PreAuthorize("hasAuthority('bnt.processType.add')")
  @ApiOperation(value = "新增")
  @PostMapping("save")
  public Result save(@RequestBody ProcessType processType) {
    processTypeService.save(processType);
    return Result.ok();
  }
  
  @PreAuthorize("hasAuthority('bnt.processType.update')")
  @ApiOperation(value = "修改")
  @PutMapping("update")
  public Result updateById(@RequestBody ProcessType processType) {
    processTypeService.updateById(processType);
    return Result.ok();
  }
  
  @PreAuthorize("hasAuthority('bnt.processType.remove')")
  @ApiOperation(value = "删除")
  @DeleteMapping("remove/{id}")
  public Result remove(@PathVariable Long id) {
    processTypeService.removeById(id);
    return Result.ok();
  }
  
  @ApiOperation(value = "获取全部审批分类")
  @GetMapping("findAll")
  public Result findAll() {
    return Result.ok(processTypeService.list());
  }
}
